package cn.bgs.common;


import com.auth0.jwt.JWT;
import com.auth0.jwt.algorithms.Algorithm;
import org.springframework.stereotype.Component;

import java.util.Date;

@Component
public class TokenUtil {

    /**
     * 过期时间5分钟
     */
    private static final long EXPIRE_TIME = 60 * 60 * 1000;
    public static String getToken(String email, String sign){
        String token = "";
        Date date = new Date(System.currentTimeMillis() + EXPIRE_TIME);
        // 将 user id 保存到 token 里面  作为载荷
        token= JWT.create().withAudience(email)
                //60分钟后token过期
                .withExpiresAt(date)
                .sign(Algorithm.HMAC256(sign));
        return token;
    }

}
